package com.twu.biblioteca.menu;

import com.twu.biblioteca.Book;
import com.twu.biblioteca.Index;
import com.twu.biblioteca.Reserver;
import com.twu.biblioteca.user.User;

import java.io.IOException;

public class BookList extends MenuItem {
    private static final String PROMPT = "Enter any key to go back to main menu.";

    protected final Index index;
    protected final MenuInputReader reader;

    public BookList(String title, User user, Index index, MenuInputReader reader)
    {
        super(title, user);
        this.index = index;
        this.reader = reader;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(title + "\n");
        for(Book book : index.getBooks())
        {
            sb.append(book.toString() + "\n");
        }
        sb.append("\n" + PROMPT + "\n");
        return sb.toString();
    }

    @Override
    public void run()
    {
        try
        {
            reader.readString();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
